﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using W_Fish.Models;

namespace W_Fish.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/
        int Max = 100000;
        FishManagement_Timkiemx db = new FishManagement_Timkiemx();
        #region[List]


        public ActionResult List()
        {

            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> "; 
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> "; 
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> " ;
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";                               
                        menu += "</tr> " ;
                        menu += "<tr> " ;
                        menu += "<td colspan=\"5\"> " ;
                        menu += "<table> " ;   
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {
                           
                                menu += "<tr>";
                                menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type="+i.FamiliaID+"\" style=\"color: #bde6e9\">"+i.FamilialName+"</a></td>";                                                               
                                menu += "</tr>";
                                menu += "<tr>";
                                menu += "<td>";     
                            var chi = (from c in db.Genus where  c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c ).ToList<Genu>();                           
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">"+curc.GenusName+"</a><br />";
                            }
                             menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion

            List<SelectListItem> dropdownItems = new List<SelectListItem>();
            dropdownItems.AddRange(new[]{
                            new SelectListItem() { Text = "Loài ", Value = "1" },
                            new SelectListItem() { Text = "Chi", Value = "2" },
                            new SelectListItem() { Text = "Họ", Value = "3" },
                            new SelectListItem() { Text= "Bộ", Value= "4"},
                            new SelectListItem() { Text= "Lớp", Value ="5"},
                            new SelectListItem() { Text = "Ngành", Value ="6"}});
            ViewData.Add("DropDownItems", dropdownItems);           

            string chuoi = "";

            var ca = (from x in db.Fish orderby x.CountAccess descending select x).ToList<Fish>();

            int Count;
            if (ca.Count < 20) Count = ca.Count;
            else Count = 20;
            for (int i = 0; i < Count; i++)

            {
                string[] listimage = ca[i].image.Split(new string[] { "[x]" }, StringSplitOptions.None);
               
                chuoi += "<tr>";
                chuoi += "<td align=\"left\" width=\" 100px\" height=\"100px\">";
                chuoi += "<img height= \"50\" width=\" 100\" src=\"" + listimage.First<string>() + "\"/>";
                chuoi += "</td>";
                chuoi += "<td width=\"20px\"></td><td width=\"800px\"> <table><tr>";
                chuoi += ca[i].FishName + " " + ca[i].Growth;
                chuoi += "</p></tr><tr>";
                chuoi += "<td align=\"center\"> <a href = \"/User/Information?id_fish=" + ca[i].FishID + " \"> Xem thêm </a></td>";
                chuoi += "</tr>";
                chuoi += " </table>";
                chuoi += "</td>";
                chuoi += "</tr>";

            }
            ViewBag.View = chuoi;

            return View();
        }


        [HttpPost]
        public ActionResult List(FormCollection collection)
        {
            string txtten = collection["tentimkiem"];
            int txtluachon = int.Parse(collection["luachon"]);
            if (txtten == null)
            {
                return View();
            }
            return RedirectToAction("Result", new { txtname = txtten, luachon = txtluachon });
        }

        #endregion
        #region[ListByMenu]

        public ActionResult ListByMenu( int Evi, int Type, int Id_Type )
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
            
            List<SelectListItem> dropdownItems = new List<SelectListItem>();
            dropdownItems.AddRange(new[]{
                            new SelectListItem() { Text = "Loài ", Value = "1" },
                            new SelectListItem() { Text = "Chi", Value = "2" },
                            new SelectListItem() { Text = "Họ", Value = "3" },
                            new SelectListItem() { Text= "Bộ", Value= "4"},
                            new SelectListItem() { Text= "Lớp", Value ="5"},
                            new SelectListItem() { Text = "Ngành", Value ="6"}});
            ViewData.Add("DropDownItems", dropdownItems);

            string chuoi = "";
            List<Fish> ca = new List<Fish>();

            switch (Evi)
            {
                case -1:
                    {
                        switch (Type)
                        {
                            case 1:
                                {
                                    var Ph_name = (from _ph in db.Phyla where _ph.PhylumID == Id_Type select _ph.PhylumName).ToList();

                                    var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == Id_Type select l.ClassID).ToList<int>();
                                    foreach (int k in lop)
                                    {
                                        var bo = (from o in db.Ordoes where o.OrdoID == k && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                                        foreach (int j in bo)
                                        {
                                            var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                                            foreach (int i in ho)
                                            {
                                                var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                                foreach (int curc in chi)
                                                {                            
                                                    var curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                                    foreach (Fish x in curf)
                                                    {
                                                        ca.Add(x);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    ViewBag.header = "Danh sách cá ngành " + Ph_name.First();
                                    break;
                                }
                            case 2:
                                {
                                    var Cl = (from _cl in db.ClassFish where Id_Type == _cl.ClassID select _cl.ClassName).ToList();
                                    var bo = (from o in db.Ordoes where o.ClassID == Id_Type && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                                    foreach (int j in bo)
                                    {
                                        var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                                        foreach (int i in ho)
                                        {
                                            var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                            foreach (int curc in chi)
                                            {
                                                var curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                                foreach (Fish x in curf)
                                                {
                                                    ca.Add(x);
                                                }
                                            }
                                        }
                                    }
                                    ViewBag.header = "Danh sách cá lớp " + Cl.First(); 
                                    break;
                                }
                            case 3:
                                {
                                    var Or = (from _or in db.Ordoes where _or.OrdoID == Id_Type select _or.OrdoName).ToList();
                                    var ho = (from h in db.Familias where h.OrdoID == Id_Type && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                                    foreach (int i in ho)
                                    {
                                        var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                        foreach (int curc in chi)
                                        {
                                            var curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                            foreach (Fish x in curf)
                                            {
                                                ca.Add(x);
                                            }
                                        }
                                    }
                                    ViewBag.header = "Danh sách cá bộ " + Or.First(); 
                                    break;
                                }
                            case 4:
                                {
                                    var Fa = (from _fa in db.Familias where _fa.FamiliaID == Id_Type select _fa.FamilialName).ToList();
                                    var chi = (from c in db.Genus where c.FamiliaID == Id_Type && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                    foreach (int curc in chi)
                                    {
                                        var curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                        foreach (Fish x in curf)
                                        {
                                            ca.Add(x);
                                        }
                                    }
                                    ViewBag.header = "Danh sách cá họ " + Fa.First(); 
                                    break;
                                }
                            case 5:
                                {
                                    var Ge = (from _ge in db.Genus where _ge.GenusID == Id_Type select _ge.GenusName).ToList();
                                    var curf = (from a in db.Fish where a.GenusID == Id_Type && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                    foreach (Fish x in curf)
                                    {
                                        ca.Add(x);
                                    }
                                    ViewBag.header = "Danh sách cá chi " + Ge.First(); 
                                    break;
                                }
                            default:
                                {
                                    break;
                                }
                        }
                        break;
                    }
                case 1:
                    {
                        ViewBag.header = "Danh sách cá nước lợ";
                        ca = (from _fi in db.Fish where _fi.Fi_kiemduyet == true && _fi.Environment == 1 select _fi).ToList<Fish>();
                        break;
                    }
                case 2:
                    {
                        ViewBag.header = "Danh sách cá nước mặn";
                        ca = (from _fi in db.Fish where _fi.Fi_kiemduyet == true && _fi.Environment == 2 select _fi).ToList<Fish>();
                        break;
                    }
                case 3:
                    {
                        ViewBag.header = "Danh sách cá nước ngọt";
                        ca = (from _fi in db.Fish where _fi.Fi_kiemduyet == true && _fi.Environment == 3 select _fi).ToList<Fish>();
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
           
            for (int i = 0; i < ca.Count; i++)
            {
                string[] listimage = ca[i].image.Split(new string[] { "[x]" }, StringSplitOptions.None);

                chuoi += "<tr>";
                chuoi += "<td align=\"left\" width=\" 100px\" height=\"100px\">";
                chuoi += "<img height= \"50\" width=\" 100\" src=\"" + listimage.First<string>() + "\"/>";
                chuoi += "</td>";
                chuoi += "<td width=\"20px\"></td><td width=\"800px\"> <table><tr>";
                chuoi += ca[i].FishName + " " + ca[i].Growth;
                chuoi += "</p></tr><tr>";
                chuoi += "<td align=\"center\"> <a href = \"/User/Information?id_fish=" + ca[i].FishID + " \"> Xem thêm </a></td>";
                chuoi += "</tr>";
                chuoi += " </table>";
                chuoi += "</td>";
                chuoi += "</tr>";

            }
            ViewBag.View = chuoi;

            return View();
        }


        [HttpPost]
        public ActionResult ListByMenu(FormCollection collection)
        {
            string txtten = collection["tentimkiem"];
            int txtluachon = int.Parse(collection["luachon"]);
            if (txtten == null)
            {
                return View();
            }
            return RedirectToAction("Result", new { txtname = txtten, luachon = txtluachon });
        }

        #endregion
        #region[ListPhylum]
        public ActionResult ListPhylum(int id_phylum)
        {

            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion

            var Phy = (from _phy in db.Phyla where _phy.PhylumID == id_phylum && _phy.Ph_kiemduyet==true select _phy).ToList<Phylum>();
            var Cl = (from _cl in db.ClassFish where _cl.IdPh == id_phylum && _cl.Cl_kiemduyet== true select _cl).ToList<ClassFish>();
            ViewBag.PhylumName = Phy.First().PhylumName;
            ViewBag.SH= Phy.First().PhylumBiology;
            ViewBag.live = Phy.First().PhylumHabitat;
            string chuoi= "";
            int ii= 1;
            foreach (ClassFish mem in Cl)
            {
                chuoi += "<a href=\"/User/ListClass?id_class= " + mem.ClassID + "\">" + ii + ". " + mem.ClassName + " </a> <br />";
                ii = ii + 1;
            }

            ViewBag.ListClass = chuoi;
            return View();
       
        }
        #endregion
        #region[ListClass]
        public ActionResult ListClass(int id_class)
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
            
            var Cls = (from _cls in db.ClassFish where _cls.ClassID == id_class && _cls.Cl_kiemduyet == true select _cls).ToList<ClassFish>();
            var Or = (from _or in db.Ordoes where _or.ClassID == id_class && _or.Or_kiemduyet == true select _or).ToList<Ordo>();
            ViewBag.ClassName = Cls.First().ClassName;
            ViewBag.SH = Cls.First().ClassBiology;
            ViewBag.live = Cls.First().ClassHabitat;
            string chuoi = "";
            int ii = 1;
            foreach (Ordo mem in Or)
            {
                chuoi += "<a href=\"/User/ListOrdo?id_ordo= " + mem.OrdoID + "\">" + ii + ". " + mem.OrdoName + " </a> <br />";
                ii = ii + 1;
            }

            ViewBag.ListOrdo = chuoi;
            return View();
        }
        #endregion
        #region[ListOrdo]
        public ActionResult ListOrdo(int id_ordo)
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
            var Or = (from _or in db.Ordoes where _or.OrdoID == id_ordo && _or.Or_kiemduyet == true select _or).ToList<Ordo>();
            var Fa = (from _fa in db.Familias where _fa.OrdoID == id_ordo && _fa.Fa_kiemduyet == true select _fa).ToList<Familia>();
            ViewBag.ClassName = Or.First().OrdoName;
            ViewBag.SH = Or.First().OrdoBiology;
            ViewBag.live = Or.First().OrdoHabitat;
            string chuoi = "";
            int ii = 1;
            foreach (Familia mem in Fa)
            {
                chuoi += "<a href=\"/User/ListFamily?id_family= " + mem.FamiliaID + "\">" + ii + ". " + mem.FamilialName + " </a> <br />";
                ii = ii + 1;
            }

            ViewBag.ListFamily = chuoi;
            return View();
        }

        #endregion
        #region[Listfamily]
        public ActionResult ListFamily(int id_family)
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion

            var Fa = (from _fa in db.Familias where _fa.FamiliaID == id_family && _fa.Fa_kiemduyet == true select _fa).ToList<Familia>();
            var Ge = (from _ge in db.Genus where _ge.FamiliaID == id_family && _ge.Ge_kiemduyet == true select _ge).ToList<Genu>();
            ViewBag.ClassName = Fa.First().FamilialName;
            ViewBag.SH = Fa.First().FamilialBiology;
            ViewBag.live = Fa.First().FamilialHabitat;
            string chuoi = "";
            int ii = 1;
            foreach (Genu mem in Ge)
            {
                chuoi += "<a href=\"/User/ListGenus?id_genus= " + mem.GenusID + "\">" + ii + ". " + mem.GenusName + " </a> <br />";
                ii = ii + 1;
            }

            ViewBag.ListGenus = chuoi;
            return View();            
        }
        #endregion
        #region[ListGenus]
        public ActionResult ListGenus(int id_genus)
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
            var Ge = (from _ge in db.Genus where _ge.GenusID == id_genus && _ge.Ge_kiemduyet == true select _ge).ToList<Genu>();
            var Fi = (from _fi in db.Fish where _fi.GenusID == id_genus && _fi.Fi_kiemduyet == true select _fi).ToList<Fish>();
            ViewBag.ClassName = Ge.First().GenusName;
            ViewBag.SH = Ge.First().GenusBiology;
            ViewBag.live = Ge.First().GenusHabitat;
            string chuoi = "";
            int ii = 1;
            foreach (Fish mem in Fi)
            {
                chuoi += "<a href=\"/User/Information?id_fish=" + mem.FishID + "\">" + ii + ". " + mem.FishName + " </a> <br />";
                ii = ii + 1;
            }

            ViewBag.ListFish = chuoi;
            return View();
        }
        #endregion
        #region[Info]
        public ActionResult Information(int id_fish)
        {

            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
            string a = "";
            var info = (from tt in db.Fish where tt.FishID == id_fish && tt.Fi_kiemduyet == true select tt);

            Fish cur = new Fish();
            cur = info.First();
            
            int Ge_ID = cur.GenusID;
            var ge = (from ttge in db.Genus where ttge.GenusID == Ge_ID && ttge.Ge_kiemduyet == true select ttge);

            int Fa_ID = ge.First().FamiliaID;
            var fa = (from ttfa in db.Familias where ttfa.FamiliaID == Fa_ID && ttfa.Fa_kiemduyet == true select ttfa);

            int Or_ID = fa.First().OrdoID;
            var or = (from ttor in db.Ordoes where ttor.OrdoID == Or_ID && ttor.Or_kiemduyet == true select ttor);

            int Cl_ID = or.First().ClassID;
            var cl = (from ttcl in db.ClassFish where ttcl.ClassID == Cl_ID && ttcl.Cl_kiemduyet == true select ttcl);


            ClassFish myclass = new ClassFish();
            myclass = cl.First();

            int Ph_ID = myclass.IdPh;

            var ph = (from ttph in db.Phyla where ttph.PhylumID == Ph_ID && ttph.Ph_kiemduyet == true select ttph);


            string[] listimage = info.First().image.Split(new string[] { "[x]" }, StringSplitOptions.None);


            int ii = 1;
            a += "<center>";
            foreach (string image in listimage)
            {
                if (ii % 2 == 0)
                {
                    a += "<img height= \"100\" width= \"200\" src=\"" + image + "\" /><br />";

                }
                else
                {
                    a += "<img height= \"100\" width= \"200\" src=\"" + image + "\" />";
                }
                ii++;
            }
            
            a += "<h3 style=\"color: #0033CC\">" + cur.FishName + "</h3>";
            a += "</center>";
            a += "<br />";
            a += "<a href = \"/User/ListPhylum?id_phylum=" + ph.First().PhylumID + "\"> Ngành " + ph.First().PhylumName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListClass?id_class=" + cl.First().ClassID + "\"> Lớp " + cl.First().ClassName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListOrdo?id_ordo=" + or.First().OrdoID + "\"> Bộ " + or.First().OrdoName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListFamily?id_family=" + fa.First().FamiliaID + "\"> Họ " + fa.First().FamilialName + " </a>";
            a += "<br />";
            a += "<a href = \"/User/ListGenus?id_genus=" + ge.First().GenusID + "\"> Chi " + ge.First().GenusName + " </a>";
            a += "<br />";
            a += "<h4><i style=\"color: #990000; margin-left: 50px;\">1. Tên cá </i></h4>";
            a += "<p>";
            a += "•	Tên loài: " + cur.FishName ;
            a += "<br />";
            a += "•	Tên chính thức: " + cur.MainName;
            a += "<br />";
            a += "•	Tên danh pháp: " + cur.Nomerclature;
            a += "<br />";
            a += "•	Tên Việt Nam: " + cur.NameVN;
            a += "<br />";
            a += "</p>";
            a += "<h4><i style=\"color: #990000 ; margin-left: 50px;\">2. Phân bố </i></h4>";
            a += "<p>";
            a += "Trong nước:" + cur.FishHabitatVN;
            a += "<br />";
            a += "Thế giới:" + cur.FishHabittatW;
            a += "<br />";
            a += "</p>";
            a += "<h4><i style=\"color: #990000 ; margin-left: 50px;\">3. Mô tả hình thái và dữ liệu sinh học </i></h4>";
            a += "<p>";
            a += "Tập tính sống: " + cur.LivingHabit;
            a += "<br />";
            a += "Dinh dướng: " + cur.Nutrition;
            a += "<br />";
            a += "Sinh trưởng: " + cur.Growth;
            a += "<br />";
            a += "Sinh sản: " + cur.Reproduction;
            a += "<br />";
            a += "</p>";
            a += "<h4><i style=\"color: #990000 ; margin-left: 50px;\">4. Đặc điểm hình thái</i></h4>";
            a += "<p>";
            if (cur.LoH_Min < 0 && cur.LoH_Max < Max) { a += "•	*Lo/H: < " + cur.LoH_Max + " <br /> "; }
            if (cur.LoH_Min > 0 && cur.LoH_Max > Max) { a += "•	*Lo/H: >" + cur.LoH_Min +  " <br /> "; }
            if (cur.LoH_Min > 0 && cur.LoH_Max < Max) { a += "•	*Lo/H: " + cur.LoH_Min + " - " + cur.LoH_Max + " <br /> "; }
            if (cur.LoT_Min < 0 && cur.LoT_Max < Max) { a += "•	*Lo/T: <" + cur.LoT_Max + "<br /> "; }
            if (cur.LoT_Min > 0 && cur.LoT_Max > Max) { a += "•	*Lo/T: >" + cur.LoT_Min + "<br /> "; }
            if (cur.LoT_Min > 0 && cur.LoT_Max < Max) { a += "•	*Lo/T: " + cur.LoT_Min + " - " + cur.LoT_Max + "<br /> "; }

            if (cur.Lolcd_Min < 0 && cur.Lolcd_Max < Max) { a += "•	  Lo/lcd: <" + cur.Lolcd_Max + " <br /> "; }
            if (cur.Lolcd_Min > 0 && cur.Lolcd_Max > Max) { a += "•	  Lo/lcd: >" + cur.Lolcd_Min + " <br /> "; }
            if (cur.Lolcd_Min > 0 && cur.Lolcd_Max < Max) { a += "•	  Lo/lcd: " + cur.Lolcd_Min + " - " + cur.Lolcd_Max + " <br /> "; }
             
            if (cur.Loccd_Min < 0 && cur.Loccd_Max < Max) { a += "•	  Lo/ccd: <" + cur.Loccd_Max + " <br /> "; }
            if (cur.Loccd_Min > 0 && cur.Loccd_Max > Max) { a += "•	  Lo/ccd: >" + cur.Loccd_Min + " <br /> "; }
            if (cur.Loccd_Min > 0 && cur.Loccd_Max < Max) { a += "•	  Lo/ccd: " + cur.Loccd_Min + " - " + cur.Loccd_Max + " <br /> "; }

            if (cur.TOt_Min < 0 && cur.TOt_Max < Max) { a += "•	  T/Ot: <" + cur.TOt_Max + " <br /> "; }
            if (cur.TOt_Min > 0 && cur.TOt_Max > Max) { a += "•	  T/Ot: >" + cur.TOt_Min + " <br /> "; }
            if (cur.TOt_Min > 0 && cur.TOt_Max < Max) { a += "•	  T/Ot: " + cur.TOt_Min + " - " + cur.TOt_Max + " <br /> "; }

            if (cur.TO_Min < 0 && cur.TO_Max < Max) { a += "•	T/O: <" + cur.TO_Max + " <br /> "; }
            if (cur.TO_Min > 0 && cur.TO_Max > Max) { a += "•	T/O: >" + cur.TO_Min + " <br /> "; }
            if (cur.TO_Min > 0 && cur.TO_Max < Max) { a += "•	T/O: " + cur.TO_Min + " - " + cur.TO_Max + " <br /> "; }

            if (cur.TOO_Min < 0 && cur.TOO_Max < Max) { a += "•	  T/OO: <" + cur.TOO_Max + " <br /> "; }
            if (cur.TOO_Min > 0 && cur.TOO_Max > Max) { a += "•	  T/OO: >" + cur.TOO_Min + " <br /> "; }
            if (cur.TOO_Min > 0 && cur.TOO_Max < Max) { a += "•	  T/OO: " + cur.TOO_Min + " - " + cur.TOO_Max + " <br /> "; }

            if (cur.Tlcd_Min < 0 && cur.Tlcd_Max < Max) { a += "•	T/lcd: <" + cur.Tlcd_Max + " <br /> "; }
            if (cur.Tlcd_Min > 0 && cur.Tlcd_Max > Max) { a += "•	T/lcd: >" + cur.Tlcd_Min + " <br /> "; }
            if (cur.Tlcd_Min > 0 && cur.Tlcd_Max < Max) { a += "•	T/lcd: " + cur.Tlcd_Min + " - " + cur.Tlcd_Max + " <br /> "; }

            if (cur.Tccd_Min < 0 && cur.Tccd_Max < Max) { a += "•	T/ccd: <" + cur.Tccd_Max + " <br /> "; }
            if (cur.Tccd_Min > 0 && cur.Tccd_Max > Max) { a += "•	T/ccd: >" + cur.Tccd_Min + " <br /> "; }
            if (cur.Tccd_Min > 0 && cur.Tccd_Max < Max) { a += "•	T/ccd: " + cur.Tccd_Min + " - " + cur.Tccd_Max + " <br /> "; }

            if (cur.Hh_Min < 0 && cur.Hh_Max < Max) { a += "•   H/h: <" + cur.Hh_Max + " <br /> "; }
            if (cur.Hh_Min > 0 && cur.Hh_Max > Max) { a += "•	H/h: >" + cur.Hh_Min + " <br /> "; }
            if (cur.Hh_Min > 0 && cur.Hh_Max < Max) { a += "•	H/h: " + cur.Hh_Min + " - " + cur.Hh_Max + " <br /> "; }

            if (cur.OOO_Min < 0 && cur.OOO_Max < Max) { a += "•	  OO/O: <" + cur.OOO_Max + " <br /> "; }
            if (cur.OOO_Min > 0 && cur.OOO_Max > Max) { a += "•	  OO/O: >" + cur.OOO_Min+ " <br /> "; }
            if (cur.OOO_Min > 0 && cur.OOO_Max < Max) { a += "•	  OO/O: " + cur.OOO_Min + " - " + cur.OOO_Max + " <br /> "; }

            if (cur.lcdccd_Min < 0 && cur.lcdccd_Max < Max) { a += "•	lcd/ccd: <" + cur.lcdccd_Max + " <br /> "; }
            if (cur.lcdccd_Min > 0 && cur.lcdccd_Max > Max) { a += "•	lcd/ccd: >" + cur.lcdccd_Min + " <br /> "; }
            if (cur.lcdccd_Min > 0 && cur.lcdccd_Max < Max) { a += "•	lcd/ccd: " + cur.lcdccd_Min + " - " + cur.lcdccd_Max + " <br /> "; }
            
            if (cur.LcmaxLcmin_Min < 0 && cur.LcmaxLcmin_Max < Max) { a += "•	Lcmax/Lcmim: <" + cur.LcmaxLcmin_Max + " <br /> " ;}
            if (cur.LcmaxLcmin_Min > 0 && cur.LcmaxLcmin_Max > Max) { a += "•	Lcmax/Lcmim: >" + cur.LcmaxLcmin_Min + " <br /> " ;}
            if (cur.LcmaxLcmin_Min > 0 && cur.LcmaxLcmin_Max < Max) { a += "•	Lcmax/Lcmim: " + cur.LcmaxLcmin_Min + " - " + cur.LcmaxLcmin_Max + " <br /> "; }
            
            if (cur.LodaD_Min < 0 && cur.LodaD_Max < Max) { a += "•	  Lo/daD: <" + cur.LodaD_Max + " <br /> ";}
            if (cur.LodaD_Min > 0 && cur.LodaD_Max > Max) { a += "•	  Lo/daD: >" + cur.LodaD_Min + " <br /> ";}
            if (cur.LodaD_Min > 0 && cur.LodaD_Max < Max) { a += "•	  Lo/daD: " + cur.LodaD_Min + " - " + cur.LodaD_Max + " <br /> "; }
            
            if (cur.PVVA_Min < 0 && cur.PVVA_Max < Max) { a += "•	P-V/V-A: <" + cur.PVVA_Max + " <br /> "; }
            if (cur.PVVA_Min > 0 && cur.PVVA_Max > Max) { a += "•	P-V/V-A: >" + cur.PVVA_Min + " <br /> "; }
            if (cur.PVVA_Min > 0 && cur.PVVA_Max < Max) { a += "•	P-V/V-A: " + cur.PVVA_Min + " - " + cur.PVVA_Max + " <br /> "; }
            
            a += "</p>";
            a += "<h4><i style=\"color: #990000 ; margin-left: 50px;\">5. Giá trị sử dụng </i></h4>";
            a += "<p>";
            a += "Giá trị khoa học: " + cur.Scientific;
            a += "<br />";
            a += "Giá trị kinh tế: " + cur.Economic;
            a += "<br />";
            a += "Hiện trạng nguồn lợi: " + cur.Resourcce;
            a += "<br />";
            a += "</p>";          
            string mt = "";
            switch (cur.Environment)
            {
                case 1:
                    {
                        mt = "Nước lợ .";
                        break;
                    }
                case 2:
                    {
                        mt = "Nước mặn. ";
                        break;
                    }
                case 3:
                    {
                        mt = "Nước ngọt. ";
                        break;
                    }
                default: { break; }
            }

            a += "</p>";
            a += "<h4><i style=\"color: #990000; margin-left: 50px;\">6. Môi trường sống: </i></h4>" + mt;
            a += "<p>";

            ViewBag.tt = a;

            cur.CountAccess = cur.CountAccess + 1;
            UpdateModel(cur);
            db.SaveChanges();

            return View();
        }

        #endregion     
        #region[selectbystype]
        public ActionResult UserByStype()
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
            return View();
        }
        
        [HttpPost]
        public ActionResult UserByStype(FormCollection collection)
        {
            double stxtlo; double stxtH; double stxtt; double stxtlcd; double stxtccd; double stxtot; double stxto; double stxtoo; double stxthh; double stxtlcmax; double stxtlcmin; double stxtdaD; double stxtPV; double stxtVA;
            
            try { stxtlo = double.Parse(collection["Lo"]); }
            catch { stxtlo = 0.0; }
            try {  stxtH = double.Parse(collection["H"]); }
            catch { stxtH = 0.0; }
            try {  stxtt = double.Parse(collection["T"]); }
            catch { stxtt = 0.0; }
            try {  stxtlcd = double.Parse(collection["Lcd"]); }
            catch { stxtlcd = 0.0; }
            try {  stxtccd = double.Parse(collection["ccd"]); }
            catch { stxtccd = 0.0; }
            try {  stxtot = double.Parse(collection["Ot"]); }
            catch { stxtot = 0.0; }
            try {  stxto = double.Parse(collection["O"]); }
            catch { stxto = 0.0; }
            try {  stxtoo = double.Parse(collection["OO"]); }
            catch { stxtoo = 0.0; }
            try {  stxthh = double.Parse(collection["h"]); }
            catch { stxthh = 0.0; }
            try {  stxtlcmax = double.Parse(collection["Lc_max"]); }
            catch { stxtlcmax = 0.0; }
            try {  stxtlcmin = double.Parse(collection["Lc_min"]); }
            catch { stxtlcmin = 0.0; }
            try {  stxtdaD = double.Parse(collection["daD"]); }
            catch { stxtdaD = 0.0; }
            try {  stxtPV = double.Parse(collection["P-V"]); }
            catch { stxtPV = 0.0; }
            try {  stxtVA = double.Parse(collection["V-A"]); }
            catch { stxtVA = 0.0; }
            return RedirectToAction("ResultStype", new { txtlo = stxtlo, txtH = stxtH, txtt = stxtt, txtlcd = stxtlcd, txtccd = stxtccd, txtot = stxtot, txto = stxto, txtoo = stxtoo, txthh = stxthh, txtlcmax = stxtlcmax, txtlcmin = stxtlcmin, txtdaD = stxtdaD, txtPV = stxtPV, txtVA = stxtVA });
        }     

   
        #endregion
        #region[ResultStype]
        public ActionResult ResultStype(double txtlo, double txtH, double txtt, double txtlcd, double txtccd, double txtot, double txto, double txtoo , double txthh , double txtlcmax, double txtlcmin , double txtdaD , double txtPV , double txtVA)
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
            Tile a = new Tile();

            try { a.Hh =  txtH/txthh; }
            catch { a.Hh = 0.0; }
            try { a.lcdccd = txtlcd/txtccd; }
            catch { a.lcdccd = 0; }
            try { a.LcmaxLcmin = txtlcmax/txtlcmin; }
            catch { a.LcmaxLcmin = 0; }
            try { a.Loccd = txtlo / txtccd; }
            catch { a.Loccd = 0; }
            try { a.LodaD = txtlo / txtdaD; }
            catch { a.LodaD = 0; }
            try { a.OOO = txto / txtoo; }
            catch { a.OOO = 0; }
            try { a.PVVA = txtPV / txtVA; }
            catch { a.PVVA = 0; }
            try { a.Tccd = txtt / txtccd; }
            catch { a.Tccd = 0; }
            try { a.Tlcd = txtt / txtlcd; }
            catch { a.Tlcd = 0; }
            try { a.TO = txtt / txto; }
            catch { a.TO = 0; }
            try { a.TOO = txtt / txtoo; }
            catch { a.TOO = 0; }
            try { a.LoH = txtlo / txtH;}
            catch{ a.LoH = 0;}
            try {a.Lolcd = txtlo / txtlcd;}
            catch {a.Lolcd = 0;}
            try {a.LoT = txtlo/ txtt;}
            catch{a.LoT = 0;}
            try { a.TOt = txtt / txtot; }
            catch { a.TOt = 0; }
           
            var Kq = (from _kq in db.Fish
                      where _kq.Fi_kiemduyet == true && _kq.Hh_Min < a.Hh && _kq.lcdccd_Min < a.lcdccd && _kq.LcmaxLcmin_Min < a.LcmaxLcmin && _kq.Loccd_Min < a.Loccd && _kq.LodaD_Min < a.LodaD && _kq.LoH_Min < a.LoH && _kq.Lolcd_Min < a.Lolcd && _kq.LoT_Min < a.LoT && _kq.OOO_Min < a.OOO && _kq.PVVA_Min < a.PVVA && _kq.Tccd_Min < a.Tccd && _kq.Tlcd_Min < a.Tlcd && _kq.TO_Min < a.TO && _kq.TOO_Min < a.TOO && _kq.TOt_Min < a.TOt
                                                    && _kq.Hh_Max > a.Hh && _kq.lcdccd_Max > a.lcdccd && _kq.LcmaxLcmin_Max > a.LcmaxLcmin && _kq.Loccd_Max < a.Loccd && _kq.LodaD_Max < a.LodaD && _kq.LoH_Max > a.LoH && _kq.Lolcd_Max > a.Lolcd && _kq.LoT_Max > a.LoT && _kq.OOO_Max > a.OOO && _kq.PVVA_Max > a.PVVA && _kq.Tccd_Max > a.Tccd && _kq.Tlcd_Max > a.Tlcd && _kq.TO_Max > a.TO && _kq.TOO_Max > a.TOO && _kq.TOt_Max > a.TOt
                      select _kq).ToList<Fish>();

            string chuoi1 = " ";
            foreach (Fish onefish in Kq)
            {
                string ima = onefish.image;
                string[] oneimage = ima.Split(new string[] { "[x]" }, StringSplitOptions.None);
                chuoi1 += "<tr>";
                chuoi1 += "<td align=\"left\" width=\" 100px\" height=\"100px\">";
                chuoi1 += "<img height= \"50\" width=\" 100\" src=\"" + oneimage.First() + "\"/>";
                chuoi1 += "</td>";
                chuoi1 += "<td width=\"20px\"></td><td width=\"800px\"> <table><tr>";
                chuoi1 += onefish.FishName + " " + onefish.Growth;
                chuoi1 += "</p></tr><tr>";
                chuoi1 += "<td align=\"center\"> <a href = \"/User/Information?id_fish=" + onefish.FishID + " \"> Xem thêm </a></td>";
                chuoi1 += "</tr>";
                chuoi1 += " </table>";
                chuoi1 += "</td>";
                chuoi1 += "</tr>";
            }
            ViewBag.sodo = chuoi1;

            return View();
           
        }
        #endregion  
        #region[Result]
        public ActionResult Result(string txtname, int luachon)
        {
            #region[Menu]
            string menu = "";

            List<Phylum> nganh = (from ng in db.Phyla where ng.Ph_kiemduyet == true select ng).ToList<Phylum>();
            foreach (Phylum m in nganh)
            {
                menu += "<tr> ";
                menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=1&&Id_Type=" + m.PhylumID + "\" style=\"color: #bde6e9\">" + m.PhylumName + "</a></td> ";
                menu += "</tr> ";
                menu += "<tr> ";
                menu += "<td colspan=\"5\"> ";
                menu += "<table> ";
                var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.IdPh == m.PhylumID select l).ToList<ClassFish>();
                foreach (ClassFish k in lop)
                {
                    menu += "<tr> ";
                    menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=2&&Id_Type=" + k.ClassID + "\" style=\"color: #bde6e9\">" + k.ClassName + "</a></td> ";
                    menu += "</tr> ";
                    menu += "<tr> ";
                    menu += "<td colspan=\"5\"> ";
                    menu += "<table> ";
                    var bo = (from o in db.Ordoes where o.Or_kiemduyet == true && o.ClassID == k.ClassID select o).ToList<Ordo>();
                    foreach (Ordo j in bo)
                    {
                        menu += "<tr> ";
                        menu += "<td ><a href=\"/User/ListByMenu?Evi=-1&&Type=3&&Id_Type=" + j.OrdoID + "\" style=\"color: #bde6e9\">" + j.OrdoName + "</a></td> ";
                        menu += "</tr> ";
                        menu += "<tr> ";
                        menu += "<td colspan=\"5\"> ";
                        menu += "<table> ";
                        var ho = (from h in db.Familias where h.Fa_kiemduyet == true && h.OrdoID == j.OrdoID select h).ToList<Familia>();
                        foreach (Familia i in ho)
                        {

                            menu += "<tr>";
                            menu += "<td><a href=\"/User/ListByMenu?Evi=-1&&Type=4&&Id_Type=" + i.FamiliaID + "\" style=\"color: #bde6e9\">" + i.FamilialName + "</a></td>";
                            menu += "</tr>";
                            menu += "<tr>";
                            menu += "<td>";
                            var chi = (from c in db.Genus where c.Ge_kiemduyet == true && c.FamiliaID == i.FamiliaID select c).ToList<Genu>();
                            foreach (Genu curc in chi)
                            {
                                menu += " <a href=\"/User/ListByMenu?Evi=-1&&Type=5&&Id_Type=" + curc.GenusID + "\" style=\"color: #bde6e9\">" + curc.GenusName + "</a><br />";
                            }
                            menu += "</td></tr>";
                        }
                        menu += "</table> </td></tr>";
                    }
                    menu += "</table> </td></tr>";
                }
                menu += "</table> </td></tr>";
            }


            ViewBag.Menu = menu;
            #endregion
 
            List<Fish> ds = new List<Fish>();
            
            switch (luachon)
            {
                case 1:

                    {
                        ds = (from a in db.Fish where a.FishName.Contains(txtname) && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                        break;
                    }
                case 2:
                    {
                        List<Fish> curf;
                        List<int> chi = (from b in db.Genus where b.Ge_kiemduyet == true && b.GenusName.Contains(txtname) select b.GenusID).ToList<int>();
                        foreach (int i in chi)
                        {
                            curf = new List<Fish>();
                            curf = (from a in db.Fish where a.GenusID == i && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                            foreach (Fish x in curf)
                            {
                                ds.Add(x);
                            }
                        }
                        break;
                    }
                case 3:
                    {
                        List<Fish> curf;
                        List<int> ho = (from h in db.Familias where h.FamilialName.Contains(txtname) && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                        foreach (int i in ho)
                        {
                            var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                            foreach (int curc in chi)
                            {
                                curf = new List<Fish>();
                                curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                foreach (Fish x in curf)
                                {
                                    ds.Add(x);
                                }
                            }
                        }

                        break;
                    }
                case 4:
                    {
                        List<Fish> curf;
                        List<int> bo = (from o in db.Ordoes where o.OrdoName.Contains(txtname) && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                        foreach (int j in bo)
                        {
                            var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                            foreach (int i in ho)
                            {
                                var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                foreach (int curc in chi)
                                {
                                    curf = new List<Fish>();
                                    curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                    foreach (Fish x in curf)
                                    {
                                        ds.Add(x);
                                    }
                                }
                            }
                        }

                        break;
                    }
                case 5:
                    {
                        List<Fish> curf;
                        List<int> lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.ClassName.Contains(txtname) select l.ClassID).ToList<int>();
                        foreach (int k in lop)
                        {
                            var bo = (from o in db.Ordoes where o.OrdoID == k && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                            foreach (int j in bo)
                            {
                                var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                                foreach (int i in ho)
                                {
                                    var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                    foreach (int curc in chi)
                                    {
                                        curf = new List<Fish>();
                                        curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                        foreach (Fish x in curf)
                                        {
                                            ds.Add(x);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                case 6:
                    {
                        List<Fish> curf;
                        List<int> nganhca = (from ng in db.Phyla where ng.Ph_kiemduyet == true && ng.PhylumName.Contains(txtname) select ng.PhylumID).ToList<int>();
                        foreach (int m in nganhca)
                        {
                            var lop = (from l in db.ClassFish where l.Cl_kiemduyet == true && l.ClassID == m select l.ClassID).ToList<int>();
                            foreach (int k in lop)
                            {
                                var bo = (from o in db.Ordoes where o.OrdoID == k && o.Or_kiemduyet == true select o.OrdoID).ToList<int>();
                                foreach (int j in bo)
                                {
                                    var ho = (from h in db.Familias where h.FamiliaID == j && h.Fa_kiemduyet == true select h.FamiliaID).ToList<int>();
                                    foreach (int i in ho)
                                    {
                                        var chi = (from c in db.Genus where c.FamiliaID == i && c.Ge_kiemduyet == true select c.GenusID).ToList<int>();
                                        foreach (int curc in chi)
                                        {
                                            curf = new List<Fish>();
                                            curf = (from a in db.Fish where a.GenusID == curc && a.Fi_kiemduyet == true orderby a.FishName select a).ToList();
                                            foreach (Fish x in curf)
                                            {
                                                ds.Add(x);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                default: break;
            }

                    string chuoi1 = " ";
                    foreach (Fish onefish in ds)
                    {
                        string a = onefish.image;
                        string[] oneimage = a.Split(new string[] {"[x]"}, StringSplitOptions.None);
                        chuoi1 += "<tr>";
                        chuoi1 += "<td align=\"left\" width=\" 100px\" height=\"100px\">";
                        chuoi1 += "<img height= \"50\" width=\" 100\" src=\"" + oneimage.First() + "\"/>";
                        chuoi1 += "</td>";
                        chuoi1 += "<td width=\"20px\"></td><td width=\"800px\"> <table><tr>";
                        chuoi1 += onefish.FishName + " " + onefish.Growth;
                        chuoi1 += "</p></tr><tr>";
                        chuoi1 += "<td align=\"center\"> <a href = \"/User/Information?id_fish=" + onefish.FishID + " \"> Xem thêm </a></td>";
                        chuoi1 += "</tr>";
                        chuoi1 += " </table>";
                        chuoi1 += "</td>";
                        chuoi1 += "</tr>";
                    }
                    ViewBag.View = chuoi1;

                    return View();
            }

        #endregion

        }
    }